﻿using ATEC.ATCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
using DoModelExample;
using SSDPNET;
using ATEC.ATDataCoreNET;

namespace ATLoadNet
{
    [ATEC.ATCore.ATLoadAttribute(ATTaskID = "ATLoadNet")]
    public class ATLoadNet : ATEC.ATCore.ATLoad
    {
        internal static ATLoad s_App;

        public ATLoadNet(System.IntPtr atDesc)
            : base(atDesc)
        {
            string exePath = Assembly.GetExecutingAssembly().Location;
            string folder = Path.GetDirectoryName(exePath);
            string sAtrc = Path.Combine(folder, "..\\SSDP\\ATLoadNetTools.atrc");
            int nLoad = SSDPNET.Ribbon.Ribbon.LoadRibbon(sAtrc);
            //监听db打开事件
            NewDesignFileEvent += ATLoadNet_NewDesignFileEvent;

            s_App = this;
        }

        /// <summary>
        /// 监听db打开事件，实现的内容用户自定义
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="zf5fce64e32"></param>
        private void ATLoadNet_NewDesignFileEvent(ATLoad sender, NewDesignFileEventArgs zf5fce64e32)
        {
            if(zf5fce64e32.WhenCode == NewDesignFileEventArgs.When.AfterDesignFileOpen)
            {
                //当事件是 打开db时，执行需要的函数
                ATProject masterATProject = SSDPNET.ATObjFuncs.ProjectObjGetMasterProject();
                string dbFileName = masterATProject.GetFileName();

                CreateNewProject.NewDesignFile(dbFileName);
            }
        }

        public static ATLoad GetApp()
        {
            return s_App;
        }

        protected override int Run(string[] cmdline)
        {
            ATLoadNet.s_App = this;
            return 0;
        }
    };
}
